<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>26题寻找质数</title>
    <script>
        function caculate(flag) {
            var num = prompt(flag ? '请输入正确的正整数' : '请输入一个正整数');
            if (!/^[0-9]*$/i.test(num)) {
                caculate(true);
                return;
            }
            
            let len = parseInt(num);
            let arr = [1];
            for (let i = 2; i <= len; i++) {
                if (len % i === 0) {
                    arr.push(i);
                }
            }

            if (arr.length === 2) {
                alert(`${num}是一个质数`);
            } else {
                alert(`${num}不是一个质数`);
            }
        }
    </script>
</head>
<body>
    <p>
        点击按钮开始输入，查看该数是否是质数<input type="button" value="输入" onclick="caculate()">
    </p>
</body>
</html>